package com.example.administrator.himalaya.live_button_adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.himalaya.R;
import com.example.administrator.himalaya.entity.live_button_entity.Live_Button_Entity;
import com.squareup.picasso.Picasso;

import java.util.List;


public class Live_Button_Adapter extends BaseAdapter{
    private Context context;
    private List<Live_Button_Entity.DataEntity.Entity> datas;
    private LayoutInflater inflater;

    public Live_Button_Adapter(Context context, List<Live_Button_Entity.DataEntity.Entity> datas) {
        this.context = context;
        this.datas = datas;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.china,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        if(datas.get(position).getProgramName()!=null) {
            holder.mTitle.setText(datas.get(position).getName());
            holder.mIng.setText("正在直播:" + datas.get(position).getProgramName());
        }else {
            holder.mIng.setText("正在直播:" + datas.get(position).getName());
        }
        holder.mPerson.setText("在线:"+datas.get(position).getProgramScheduleId());
        String img = datas.get(position).getCoverLarge();
        Picasso.with(context).load(img).into(holder.mImageView);
        return convertView;
    }
    static class ViewHolder{
        ImageView mImageView;
        TextView mTitle;
        TextView mIng;
        TextView mPerson;

        public ViewHolder(View view) {
            mImageView = (ImageView) view.findViewById(R.id.china_image);
            mTitle = (TextView) view.findViewById(R.id.china_title);
            mIng = (TextView) view.findViewById(R.id.china_ing);
            mPerson = (TextView) view.findViewById(R.id.china_per);
        }
    }
}

